
// 子表删除行逻辑

import deleSubTableRows from '../../request-functions/deleteSubTableRows';
import {
    toast
} from 'nc-lightapp-front';
import deepCopy from '../../../../public/functions/deep-copy';

import language from '../../language';

export default async function(tableId, indexList) {
    const {
        cardTable: {
            delRowsByIndex,
            getAllRows
        },
        form: {
            getAllFormValue
        }
    } = this.props;

    const {
        humanResourceOrganizationValue: {
            refpk
        },
        pageFrom
    } = this.state;

    let formData = deepCopy(getAllFormValue('hi_psnjob_h'));
    let tableData = deepCopy(getAllRows(tableId));

    let postData = {
        func_type: '2',
        model: {
            areacode: tableId,
            rows: []
        },
        pk_org: refpk,
        pk_psnjob: formData.rows[0].values['pk_psnjob'].value,
        table_code: tableId,
        ui_state: pageFrom === 'add' ? 1 : 2
    };

    indexList.map((item) => {
        postData.model.rows.push(tableData[item]);
    });

    try {
        // 删除子表某行的时候报错信息处理
        let res = await deleSubTableRows(postData);

        if(res.success) {
            toast({
                color: 'success',
                content: language['hi6007-000006']/* 国际化处理： 删除成功*/
            });
        }
    }
    catch(e) {
    }
    
    delRowsByIndex(tableId, indexList);
}
